package search

import (
	"GoTY/api"
	"GoTY/query"
	"bufio"
	"os"

	"fmt"
	"strings"
)

func Search(invidious, region string, numberCase, numberArray int, subChannel []string) []api.ApiResponse {
	var url string
	switch numberCase {
	case 0:
		url = fmt.Sprintf("%s/api/v1/channels/%s/videos", invidious, subChannel[numberArray])
	case 1:
		url = fmt.Sprintf("%s/api/v1/trending/?region=%s", invidious, strings.Trim(region, "\n\t "))
	case 2:
		scanner := bufio.NewScanner(os.Stdin)
		scanner.Scan()
		searchContent := scanner.Text()
		content := strings.ReplaceAll(searchContent, " ", "+")
		url = fmt.Sprintf("%sapi/v1/search?q=%s&type=video&region=%s", invidious, content, strings.Trim(region, "\n\t "))
	}
	return query.Query(url)
}
